    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="">
        <tr>
          <td width="16%">&nbsp;</td>
          <td width="80%"><h1>Корзина</h1></td>
      </tr>
    </table>
    <? 
    $this->load->helper('file');
    ?>
    
                  <script type="text/javascript">
                <!--
                  var Amounts = [

                  <?
                  $i=0;
                  foreach ($query->result() as $add){
                  $i++;
                    echo "'$add->store'";
                    if($i != $query->num_rows())
                      echo ",";
                    
                  }
                  
                  ?>];
                  var Price = [
                  <?
                  $i=0;
                  foreach ($query->result() as $add){
                  $i++; 
                 	echo "'$add->price'";
          				if($i != $query->num_rows())
                      		echo ",";
          				}
          				?>
                  ];
                  function RecalcTotalPrice()
                  {
                  var Total = 0;
                  for (var c = 0; c != Price.length; c++)
                  {
                  var inp = document.getElementById (Amounts[c]);
                  if (!inp) return;
                  var amount = parseInt (inp.value);
                  if (!(amount >= 0)) return;
                  Total += amount * Price[c];
                  
                  }
                  var TotalPrice = document.getElementById ('TotalPrice');
                  if (TotalPrice) TotalPrice.innerHTML = number_format(Total, 0, ',', ' ');
                  var DeliveryComment = document.getElementById ('DeliveryComment');
                  if (DeliveryComment) DeliveryComment.style.display = Total ? 'inline' : 'none';
                  }
                  //-->
                </script>
    
    
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="" style="margin-top:1.2em">
        <tr>
          <td width="16%"></td>
          <td width="64%">
          
           <? if ($query->num_rows() > 0){?>
           <form method="post" action="/store/buy">
           <table id="buy" cellspacing="0" width="100%">
             <tr>
                <th>&nbsp;</th>
                <th>Товар</th>
                <th>Кол-во</th>
                <th>Цена, грн</th>
                <th>&nbsp;</th>
             </tr>
				
				<? $price = 0; ?>
              <? foreach ($query->result() as $add){
    				$price=($add->price * $add->quantity)+$price;		          
 	              
               
                  $father = $this->db->query("SELECT father,article,price, id FROM articles WHERE id='$add->store' LIMIT 1");
          				$father = $father->row();
                    
                  $store = $this->db->query("SELECT name,title,father,id FROM store WHERE id='$father->father' LIMIT 1");
          				$store = $store->row();                    

                  
                
                 
                
                             

                  //Формируем полный линк к продукту
                    $level3 = $this->db->query("SELECT id,father,link FROM store WHERE id='$store->father' AND level=3 LIMIT 1");
            			$level3 = $level3->row();
            				
            		$level2 = $this->db->query("SELECT id,father,link  FROM store WHERE id='$level3->father' AND level=2 LIMIT 1");
            			$level2 = $level2->row();
            				
            		$level1 = $this->db->query("SELECT link  FROM store WHERE id='$level2->father' AND level=1 LIMIT 1");
            			$level1 = $level1->row();
          				
                  ?>  
              
              <tr>
                <td height="100">
                <? 
                $f=$father->father;
                
                $filename = "/images/store/buy/$f"  . ".jpg"; 
                
                
                $add->price = number_format($add->price, 0, ',', ' ');
                
                ?>
                <? if (read_file("./images/store/buy/$f" . '.jpg')){ ?>
                <a href="/store/catalog/<?=$level1->link?>/<?=$level2->link?>/<?=$level3->link?>/<?=$store->id?>"><img src="/images/store/buy/<?=$father->father?>.jpg" border="0" width="100"></a></td>
                <? }else{ ?>
                <img src="<? echo "/images/store/preview/$f". "_1.jpg" ?>" border="0" width="100">
                <? }?>
                <td>
                
                <a href="/store/catalog/<?=$level1->link?>/<?=$level2->link?>/<?=$level3->link?>/<?=$store->id?>/"><?=$store->title?></a>

                <br>Артикул: <?=$father->article?></td>
                <td><input type="text" size="3" id="<?=$father->id?>" name="id[<?=$add->id?>]" onkeyup="RecalcTotalPrice()" value="<?=$add->quantity?>"></td>
                <td><?=$add->price?></td>
                <td><a href="/store/del/<?=$add->id?>"><img src="/images/global/del.png" border="0" alt="Отказаться"><a></td>
             </tr> 

            <? } ?>
            
            
            <? $price = number_format($price, 0, ',', ' ');?>
            
            <tr>
                <td colspan="3" style="padding:10px 0px 10px 10px;font-size:1em;border-bottom:0;">
                  <div align="right"><strong>Итого:&nbsp;</strong></div>
                </td>
                <td style="padding:10px 0px 10px 0px;font-size:1em;border-bottom:0;">
                    <strong><span id="TotalPrice" ><?=$price?></span> грн</strong>
                </td>
                <td style="padding:10px 0 10px 0;border-bottom:0;">&nbsp;</td>
            </tr>
           </table>
            
              <br>
            
            <table border="0" cellspacing="0" cellpadding="0" width="100%" >
              <tr>
                <td width="50%" style="padding:10px 0 10px 0">&larr; <a href="/store">Продолжить выбор покупок</a></td>
                <td width="50%" style="padding:10px 0 10px 0"><div align="right"><input type="submit" value="Оформить заказ &rarr;"></div></td>
              </tr>
            </table>
            </form>
            
            <?}else{?>
              Ваша корзина пуста.
            <?}?>
          
          </td>
          <td width="16%"></td>
      </tr>
    </table>